<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


    <button>ok</button>

<script>
    var ws;

    function connectWs() {
        ws = new WebSocket("ws:127.0.0.1:8282");

        ws.onopen = function (event) {
            console.log(event);
        }
        ws.onmessage = function (p1) {
            console.log(p1.data);
        }
        ws.onerror = function (event) {
            if (event.type == "error"){
                alert("服务器连接失败，请稍后重试");
            }
            console.log(event);
        }
        ws.onclose = function (p1) {
            console.log(p1);
        }
    }

    connectWs();


</script>

</body>
</html>